/*
 * @Author: wuyinrui
 * @Date: 2021-08-24 10:00:27
 * @LastEditors: hejiajun
 * @LastEditTime: 2021-11-02 16:32:41
 * @Description:
 */
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';

// import '@/untils/rem.js';
// 解决ie11不渲染ant-vue的问题
// import 'core-js/stable';
// import 'regenerator-runtime/runtime';

// 引入时间插件
import moment from 'moment';
import 'moment/locale/zh-cn';

// 引入函数库
import { random } from 'lodash';

import 'element-plus/dist/index.css';

// 按需引入ant-vue
import { DatePicker, Button, ConfigProvider, Progress, Table, Select, Breadcrumb, message, Tooltip } from 'ant-design-vue';

// 按需引入echarts
import echarts from '@/assets/config/echarts.config';

// 引入滚动插件
import countTo from 'vue3-count-to';

// 引入自动注册全局组件文件
import globalComponents from '@/assets/js/globalComponents'; // 建议在最后处使用

// 引入全局工具类
import untils from '@/untils/common';

// 引入封装的axios
import { $http } from '@/untils/axios/request';

import axios from 'axios';

const app = createApp(App);
var { NODE_ENV } = process.env;
console.log('NODE_ENV', NODE_ENV);

// 新增全局变量
app.config.globalProperties.$echarts = echarts;
app.config.globalProperties.$moment = moment;
app.config.globalProperties.$_ = { random };
app.config.globalProperties.$untils = untils;
app.config.globalProperties.$http = $http;
app.config.globalProperties.axios = axios;
app.config.globalProperties.$message = message;

// window.addEventListener('beforeunload', () => {
//   sessionStorage.setItem('userInfo', JSON.stringify(store.state.userInfo));
// });

// 全局路由守卫
router.beforeEach(async (to, from, next) => {
    store.commit('setRouter', {
        to,
        from,
    });
    next();
});

app
  .use(store)
  .use(router)
  .use(ConfigProvider)
  .use(DatePicker)
  .use(Button)
  .use(Progress)
  .use(Table)
  .use(Select)
  .use(Breadcrumb)
  .use(countTo)
  .use(Tooltip)
  .use(globalComponents)
  .mount('#app');